import { ss } from '@/utils/storage'

const LOCAL_NAME = 'userStorage'

export interface UserInfo {
  avatar: string
  name: string
  description: string
}

export interface UserState {
  userInfo: UserInfo
}

export function defaultSetting(): UserState {
  return {
    userInfo: {
      avatar: '',
      name: '彩色之外',
      description: 'Star on <a href="https://blog.csdn.net/m0_57904695?spm=1000.2115.3001.5343" class="text-blue-500" target="_blank" >CSDN</a> / <a href="https://gitee.com/zhang-kun8888/browser-set-chartgpt-preject" class="text-blue-500" target="_blank" >仓库</a>',
    },
  }
}

export function getLocalState(): UserState {
  const localSetting: UserState | undefined = ss.get(LOCAL_NAME)
  return { ...defaultSetting(), ...localSetting }
}

export function setLocalState(setting: UserState): void {
  ss.set(LOCAL_NAME, setting)
}
